<!--
 * @Author: Bo
 * @Date: 2022-03-24 11:24:29
-->
<template>
  <div
    class="artical-item"
    :class="{ 'artical-item--search': type === 'search' }"
  >
    <div class="artical-item--title" @click="jump">{{ item.title }}</div>
    <div class="artical-item--des">
      <div class="des-img" v-if="item.cover">
        <img :src="item.cover" alt="" />
      </div>
      <div class="des-content">
        {{ item.sub_description }}
      </div>
    </div>
    <div class="artical-item--bottom" v-if="type === 'list'">
      <div class="op-list">
        <el-button type="warning" @click="handleLikeClick(item)">
          <el-icon><caret-top /></el-icon>点赞（{{ item.like }}）
        </el-button>
        <el-button type="warning" @click="handleHateClick">
          <el-icon><caret-bottom /></el-icon>
        </el-button>
      </div>

      <div class="time">
        {{ timestampToDate(item.create_time).substring(0, 10) }}
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import router from '../../router/router'
import { setBlogLike } from '../../api/api'
import { timestampToDate } from '/@/utils/date'
const props = defineProps(['item', 'type'])
function jump() {
  router.push({
    name: 'Artical',
    params: {
      id: props.item.uu_id
    }
  })
}
function handleLikeClick(item: any) {
  setBlogLike({ uuid: item.uu_id }).then((res: any) => {
    if (res.code === 1) {
      //   if (messageBox) {
      //     this.messageBox.close()
      //     this.messageBox = null
      //   }
      //   this.messageBox = this.$message.success('设置成功')

      item.like = parseInt(item.like) + 1
    }
  })
}
function handleHateClick() {
  console.log(1)
}
</script>
<style scoped lang="less">
.artical-item {
  padding: 30px 20px;
  border-bottom: 1px solid #eee;

  &.artical-item--search {
    box-shadow: 0 0 5px #e5e5e5;
    margin: 20px 10px;
  }

  .artical-item--title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 15px;
    cursor: pointer;
    color: #000;
    transition: 0.5s;

    &:hover {
      color: chocolate;
    }
  }

  .artical-item--des {
    font-size: 14px;
    line-height: 28px;
    display: flex;
    .des-img {
      margin-right: 20px;
      img {
        width: auto;
        height: 110px;
        border-radius: 5px;
      }
    }
  }
  .artical-item--bottom {
    margin-top: 15px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;

    .time {
      margin-right: 10px;
      margin-bottom: 5px;
      font-size: 13px;
    }
  }
}
</style>
